<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>订单完成报表</title>
  <style>
    /* 设置已超期行颜色 */
    .el-table .warning-row {
      background-color: #fef0f0;
      color: #f56c6c;
    }

    .lable {
      padding: 0 3px;
    }

    .red {
      color: red;
    }

    .blue {
      color: blue;
    }

    .green {
      color: green;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="'订单完成报表'"></vue2-report-header>
    <div style="padding:5px 10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules">
        <el-form-item label="主制分厂:" prop="factoryid">
          <el-select v-model="queryInfo.factoryid" placeholder="请选择主制分厂" clearable filterable @change="bindControl">
            <el-option v-for="f in factoryList" :key="f.factoryname" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="责任工区:">
          <el-select v-model="queryInfo.workcenterid" placeholder="请选择工区" clearable filterable>
            <el-option v-for="w in workcenterList" :key="w.workcenterid" :label="w.workcentername"
              :value="w.workcenterid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="开卡人:" prop="starter">
          <el-select v-model="queryInfo.starter" placeholder="请选择开卡人" clearable filterable>
            <el-option v-for="p in starterList" :key="p.employeeid" :label="p.fullname" :value="p.employeeid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="开卡日期:" prop="startdate">
          <el-date-picker v-model="queryInfo.startdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="机型:" prop="productfamilyname">
          <el-select v-model="queryInfo.productfamilyname" placeholder="请选择机型" clearable filterable>
            <el-option v-for="p in productfamilyList" :key="p.productfamilyname" :label="p.productfamilyname"
              :value="p.productfamilyname">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop='mfgordername' label="订单号:">
          <el-autocomplete v-model.trim="queryInfo.mfgordername" placeholder="请输入订单号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchMfgorderAsync" :value-key="'mfgordername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='productname' label="零件图号:">
          <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入零件图号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='containername' label="流水卡号:">
          <el-autocomplete v-model.trim="queryInfo.containername" placeholder="请输入流水卡号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="成检入库时间:" prop="instoredate">
          <el-date-picker v-model="queryInfo.instoredate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="完工时间:">
          <el-date-picker v-model="queryInfo.finishdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="计划完成时间:">
          <el-date-picker v-model="queryInfo.planfinishdate" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="handleSearch">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="handleExport">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column label="订单号" prop="mfgordername" width="120" sortable show-overflow-tooltip></el-table-column>
        <el-table-column label="机型" prop="familylistnames" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="零件图号" prop="productname" width="100" sortable show-overflow-tooltip></el-table-column>
        <el-table-column label="零件名称" prop="productdescription" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="流水卡号" prop="containername" width="160" sortable show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="当前工序" prop="workflowstepname" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="军种" prop="militarytype" width="80"></el-table-column>
        <el-table-column label="责任工区" prop="fromworkcentername" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="订单数" prop="mfgqty" width="60" show-overflow-tooltip></el-table-column>
        <el-table-column label="开卡数" prop="originalqty" width="60"></el-table-column>
        <el-table-column label="在制数" prop="wipqty" width="60"></el-table-column>
        <el-table-column label="完工数" prop="completeqty" width="60"></el-table-column>
        <el-table-column label="报废数" prop="scrapqty" width="60"></el-table-column>
        <el-table-column label="计划完成时间" prop="plannedcompletiondate" width="100" :formatter="splitDate">
        </el-table-column>
        <el-table-column label="完工时间" prop="completedate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="入库时间" prop="createdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="开卡人" prop="starter" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="开卡时间" prop="containerstartdate" width="120">
          <template slot-scope="scope" v-if="scope.row.containerstartdate">
            <el-popover placement="top-start" title="开卡时间取值规则如下:" width="600" trigger="hover" content="">
              <span slot="reference">
                <i class="el-icon-info" style="margin-right:5px;"></i>
                {{scope.row.containerstartdate.split('T')[0]}}
              </span>
              <p>
                1.若<strong class="red lable">【发料时间】</strong>不为空，
                <strong class="lable">【开卡时间】</strong>取<strong class="red lable">【发料时间】</strong>。
              </p>
              <p>
                2.若<strong class="red lable">【发料时间】</strong>为空，
                <strong class="blue lable">【到料时间】</strong>不为空，
                <strong class="lable">【开卡时间】</strong>取<strong class="blue lable">【到料时间】</strong>。
              </p>
              <p>
                3.若<strong class="red lable">【发料时间】</strong><strong class="blue lable">【到料时间】</strong>都为空，
                <strong class="lable">【开卡时间】</strong>取<strong class="green lable">【校对时间】</strong>。
              </p>
              <p>
                <strong class="red lable">【发料时间】</strong>：
                <span v-if="scope.row.sendmaterialdate">{{scope.row.sendmaterialdate.split('T')[0]}}</span>
                <span v-else>空</span>
              </p>
              <p>
                <strong class="blue lable">【到料时间】</strong>：
                <span v-if="scope.row.materialdate">{{scope.row.materialdate.split('T')[0]}}</span>
                <span v-else>空</span>
              </p>
              <p>
                <strong class="green lable">【校对时间】</strong>：
                <span v-if="scope.row.techniquedate">{{scope.row.techniquedate.split('T')[0]}}</span>
                <span v-else>空</span>
              </p>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="实际开卡时间" prop="originalstartdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="一次提交合格率" prop="yicitijiaohegelv" width="120"></el-table-column>
        <el-table-column label="提交合格率" prop="tijiaohegelv" width="90"></el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[12,20,50]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { getParams, fetchSuggestion, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getProductFamily, getFactory, getWorkcenterList, getFactoryUsersByRoleName, getUserInfo } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        splitDate,
        queryInfo: {
          factoryid: '',
          workcenterid: '',
          starter: '',
          startdate: [dayjs().startOf('month').format('YYYY-MM-DD'), dayjs().endOf('month').format('YYYY-MM-DD')],
          productfamilyname: '',
          mfgordername: '',
          productname: '',
          containername: '',
          instoredate: '',
          finishdate: '',
          planfinishdate: [dayjs().startOf('month').format('YYYY-MM-DD'), dayjs().endOf('month').format('YYYY-MM-DD')],
          currentPage: 1,//当前页
          pageSize: 12,//每页显示条数
        },
        total: 0,
        loading: false,
        loadingText: '',
        dataList: [],
        factoryList: [],
        workcenterList: [],
        starterList: [],
        productfamilyList: [],
        rules: {
          factoryid: [{ required: true, message: '主制分厂不能为空!', trigger: 'change' }],
          startdate: [{ required: true, message: '开卡日期不能为空!', trigger: 'change' }]
        },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        // 查询订单号
        searchMfgorderAsync(value, callback) {
          fetchSuggestion({ actionName: 'getMfgordernameAsync', name: 'mfgordername', value, callback })
        },
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback })
        },
        // 查询批次号
        searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback })
        },
        async bindControl(factoryid) {
          // 清除已选择计划员
          this.queryInfo.starter = null;
          this.queryInfo.workcenterid = null;
          if (factoryid) {
            // 查询分厂计划员
            this.starterList = await getFactoryUsersByRoleName({ factoryid, rolename: '计划员' });
            this.workcenterList = await getWorkcenterList({ factoryid, workcentertype: '是' });
          }
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        },
        //查询按钮
        async handleSearch() {
          this.$refs['queryInfoRef'].validate((valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            }
            this.getData();
          })
        },
        async handleExport() {
          this.$refs['queryInfoRef'].validate((valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            }
            this.getExportExcel();
          })
        },
        // 查询数据
        async getData() {
          this.loading = true;
          this.loadingText = '数据查询中...';
          const { data: { data, meta, total } } = await axios({
            method: 'post',
            url: '../handler/report/MfgorderCompleteRecord.ashx?action=getData',
            data: { type: 'getData', ...this.queryInfo }
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.dataList = data;
          this.total = total;
        },
        // 导出excel
        async getExportExcel() {
          const config = {
            url: '../handler/report/MfgorderCompleteRecord.ashx?action=exportExcel',
            data: { type: 'exportExcel', ...this.queryInfo }
          }
          exportExcelData(config, this);
        }
      },
      async mounted() {
        this.productfamilyList = await getProductFamily();
        this.factoryList = await getFactory();
        const userInfo = await getUserInfo({ employeeid: getParams("uid") });
        const { factoryid } = this.factoryList.some(i => i.factoryid === userInfo.factoryid) ? userInfo : this.factoryList[0];
        this.queryInfo.factoryid = factoryid;
        this.starterList = await getFactoryUsersByRoleName({ factoryid, rolename: '计划员' });
        this.workcenterList = await getWorkcenterList({ factoryid, workcentertype: '是' });
      },
      watch: { queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true } }
    })
  </script>
</body>

</html>